/*
 * AccessFlagEditorDialog.java
 *
 * Created on January 14, 2002, 10:21 AM
 *
 * Modification Log:
 * 1.00   14th Jan 2002   Tanmay   Original version.
 * 1.01   17th Jan 2002   Tanmay   Added strict flag
 *-----------------------------------------------------------------------------------------
 *       10th Sep 2003   Tanmay   Moved to SourceForge (http://classeditor.sourceforge.net)
 *-----------------------------------------------------------------------------------------
 */

package guihelper;

import classfile.AccessFlags;

/** This class provides the dialog for editing access flags.
 * <br><br>
 *
 * @author     Tanmay K. Mohapatra
 * @version    1.01, 17th Jan, 2002
 */

public class AccessFlagEditorDialog extends javax.swing.JDialog {

    AccessFlags flags; 
    
    /** Creates new form AccessFlagEditorDialog */
    public AccessFlagEditorDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    public void setAccessFlags(AccessFlags flagsIn) {
        flags = flagsIn;
        chkPublic.setSelected(flags.isPublic());
        chkPrivate.setSelected(flags.isPrivate());
        chkProtected.setSelected(flags.isProtected());
        
        chkStatic.setSelected(flags.isStatic());
        chkFinal.setSelected(flags.isFinal());
        chkSuper.setSelected(flags.isSuper());
        chkVolatile.setSelected(flags.isVolatile());
        chkTransient.setSelected(flags.isTransient());
        chkInterface.setSelected(flags.isInterface());
        chkAbstract.setSelected(flags.isAbstract());
        chkNative.setSelected(flags.isNative());
        chkSynchronized.setSelected(flags.isSynchronized());
        chkStrict.setSelected(flags.isStrict());
    }
    
    private void saveAccessFlags() {
        flags.setPublic(chkPublic.isSelected());
        flags.setPrivate(chkPrivate.isSelected());
        flags.setProtected(chkProtected.isSelected());
        
        flags.setStatic(chkStatic.isSelected());
        flags.setFinal(chkFinal.isSelected());
        flags.setSuper(chkSuper.isSelected());
        flags.setVolatile(chkVolatile.isSelected());
        flags.setTransient(chkTransient.isSelected());
        flags.setInterface(chkInterface.isSelected());
        flags.setAbstract(chkAbstract.isSelected());
        flags.setNative(chkNative.isSelected());
        flags.setSynchronized(chkSynchronized.isSelected());
        flags.setStrict(chkStrict.isSelected());
    }

    private void setAsInvalid(javax.swing.JCheckBox chk) {
        chk.setEnabled(false);
        //chk.setBackground(new java.awt.Color(255, 204, 204));
    }
    public void setValidAccessFlags(AccessFlags validFlags) {
        if(!validFlags.isPublic()) setAsInvalid(chkPublic);
        if(!validFlags.isPrivate()) setAsInvalid(chkPrivate);
        if(!validFlags.isProtected()) setAsInvalid(chkProtected);

        if(!validFlags.isStatic()) setAsInvalid(chkStatic);
        if(!validFlags.isFinal()) setAsInvalid(chkFinal);
        if(!validFlags.isSuper()) setAsInvalid(chkSuper);
        if(!validFlags.isVolatile()) setAsInvalid(chkVolatile);
        if(!validFlags.isTransient()) setAsInvalid(chkTransient);
        if(!validFlags.isInterface()) setAsInvalid(chkInterface);
        if(!validFlags.isAbstract()) setAsInvalid(chkAbstract);
        if(!validFlags.isNative()) setAsInvalid(chkNative);
        if(!validFlags.isSynchronized()) setAsInvalid(chkSynchronized);
        if(!validFlags.isStrict()) setAsInvalid(chkStrict);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        chkPublic = new javax.swing.JCheckBox();
        chkPrivate = new javax.swing.JCheckBox();
        chkProtected = new javax.swing.JCheckBox();
        chkStatic = new javax.swing.JCheckBox();
        chkFinal = new javax.swing.JCheckBox();
        chkSuper = new javax.swing.JCheckBox();
        chkVolatile = new javax.swing.JCheckBox();
        chkTransient = new javax.swing.JCheckBox();
        chkInterface = new javax.swing.JCheckBox();
        chkAbstract = new javax.swing.JCheckBox();
        chkNative = new javax.swing.JCheckBox();
        chkSynchronized = new javax.swing.JCheckBox();
        chkStrict = new javax.swing.JCheckBox();
        btnSave = new javax.swing.JButton();
        btnClose = new javax.swing.JButton();
        btnRefresh = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        setModal(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        chkPublic.setText("public");
        chkPublic.setBackground(new java.awt.Color(204, 255, 204));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
        getContentPane().add(chkPublic, gridBagConstraints);

        chkPrivate.setText("private");
        chkPrivate.setBackground(new java.awt.Color(204, 255, 204));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
        getContentPane().add(chkPrivate, gridBagConstraints);

        chkProtected.setText("protected");
        chkProtected.setBackground(new java.awt.Color(204, 255, 204));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
        getContentPane().add(chkProtected, gridBagConstraints);

        chkStatic.setText("static");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(chkStatic, gridBagConstraints);

        chkFinal.setText("final");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(chkFinal, gridBagConstraints);

        chkSuper.setText("super");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(chkSuper, gridBagConstraints);

        chkVolatile.setText("volatile");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(chkVolatile, gridBagConstraints);

        chkTransient.setText("transient");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(chkTransient, gridBagConstraints);

        chkInterface.setText("interface");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(chkInterface, gridBagConstraints);

        chkAbstract.setText("abstract");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(chkAbstract, gridBagConstraints);

        chkNative.setText("native");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(chkNative, gridBagConstraints);

        chkSynchronized.setText("synchronized");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(chkSynchronized, gridBagConstraints);

        chkStrict.setText("strict");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
        getContentPane().add(chkStrict, gridBagConstraints);

        btnSave.setText("Save");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(btnSave, gridBagConstraints);

        btnClose.setText("Close");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(btnClose, gridBagConstraints);

        btnRefresh.setText("Refresh");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(btnRefresh, gridBagConstraints);

        pack();
    }//GEN-END:initComponents

    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
        setAccessFlags(flags);
        closeDialog(null);
    }//GEN-LAST:event_btnCloseActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        saveAccessFlags();
        closeDialog(null);
    }//GEN-LAST:event_btnSaveActionPerformed

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        setAccessFlags(flags);
    }//GEN-LAST:event_btnRefreshActionPerformed

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnSave;
    private javax.swing.JCheckBox chkAbstract;
    private javax.swing.JCheckBox chkFinal;
    private javax.swing.JCheckBox chkInterface;
    private javax.swing.JCheckBox chkNative;
    private javax.swing.JCheckBox chkPrivate;
    private javax.swing.JCheckBox chkProtected;
    private javax.swing.JCheckBox chkPublic;
    private javax.swing.JCheckBox chkStatic;
    private javax.swing.JCheckBox chkStrict;
    private javax.swing.JCheckBox chkSuper;
    private javax.swing.JCheckBox chkSynchronized;
    private javax.swing.JCheckBox chkTransient;
    private javax.swing.JCheckBox chkVolatile;
    // End of variables declaration//GEN-END:variables

}
